package org.okeoe.gen.utils;


import lombok.Data;

import java.io.Serializable;

/**
 * @author : alex
 * @version ：1.0.0
 * @Date : create by 2018/2/4 17:48
 * @description ：通用返回结果对象
 * @note 注意事项
 */
@Data
public class ResultMsg implements Serializable {
    private static final long serialVersionUID = -915250813605188027L;
    private String msg;
    private String errorMessage;
    private String code;
    private boolean hasErrors;
    private boolean success;
    private Object data;

    public ResultMsg() {
    }
    public void setMsg(String msg){
        this.errorMessage =msg;
        this.msg = msg;
    }
    public static ResultMsg customMsg(String code, String msg, Object data){
        ResultMsg result = new ResultMsg();
        result.data = data;
        result.setCode(code);
        result.setMsg(msg);
        result.setErrorMessage(msg);
        return result;
    }

    public static ResultMsg success(Object data) {
        ResultMsg result = new ResultMsg();
        result.data = data;
        result.setCode(BaseCode.SUCCESS);
        result.setMsg(BaseMsg.SUCCESS);
        result.hasErrors = false;
        result.success = true;
        return result;
    }

    public static ResultMsg success() {
        ResultMsg result = new ResultMsg();
        result.hasErrors = false;
        result.setCode(BaseCode.SUCCESS);
        result.setMsg(BaseMsg.SUCCESS);
        result.success = true;
        return result;
    }

    public static ResultMsg failure(String message) {
        ResultMsg result = new ResultMsg();
        result.hasErrors = true;
        result.setCode(BaseCode.SYSTEM_ERROR);
        result.msg = message;
        result.errorMessage = message;
        return result;
    }

    public static ResultMsg failure(Object data) {
        ResultMsg result = new ResultMsg();
        result.data = data;
        result.setCode(BaseCode.SYSTEM_ERROR);
        result.setMsg(BaseMsg.SYSTEM_ERROR);
        result.setErrorMessage(BaseMsg.SYSTEM_ERROR);
        result.hasErrors = true;
        return result;
    }

}
